package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseDao;
import com.lagou.dao.impl.CourseDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.service.CourseService;

import java.util.List;

public class CourseServiceImpl implements CourseService {
    CourseDao courseDao = new CourseDaoImpl();
    @Override
    public List<Course> findCourseList() {
        List<Course> courseList = courseDao.findCourseList();
        return courseList;
    }

    @Override
    public List<Course> findCourseNameAndStatus(String course_name, String status) {
        List<Course> list = courseDao.findCourseNameAndStatus(course_name, status);
        return list;
    }

    @Override
    public String saveCourseSalesInfo(Course course) {
        CourseDao courseDao = new CourseDaoImpl();
        int i = courseDao.saveCourseSalesInfo(course);
        if (i > 0) {
            //保存成功
            String result = StatusCode.SUCCESS.toString();
            return result;

        } else {
            //保存失败
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public List<Course> findCourseById(int id) {
        CourseDao courseDao = new CourseDaoImpl();
        List<Course> list = courseDao.findCourseById(id);
        return list;
    }

    @Override
    public String UpdateCourseInfo(Course course) {
        CourseDao courseDao = new CourseDaoImpl();
        int i = courseDao.UpdateCourseInfo(course);
//        i>0
        if (i > 0) {
            String s = StatusCode.SUCCESS.toString();
            return s;
        } else {
            String  s = StatusCode.FAIL.toString();
            return s;
        }


    }
}
